/**
 * \file            lwevt.h
 * \brief           Lightweight event system
 */

#ifndef LWEVT_HDR_H
#define LWEVT_HDR_H

#include <string.h>
#include <stdint.h>
#include "lwevt_opt.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * \defgroup        LWEVT Lightweight event system
 * \brief           Lightweight event system
 * \{
 */

/**
 * \brief           Event type
 */
typedef enum {
    #define LWEVT_TYPE_BASIC(name)              name,
    #define LWEVT_TYPE_EXT(name, data)          name,
    #include "lwevt_type.h"
    LWEVT_TYPE_LAST                             /*!< Last element on the list */
} lwevt_type_t;

/**
 * \brief           Main event structure
 */
typedef struct {
    lwevt_type_t type;                          /*!< Event type */
    union {
        #define LWEVT_TYPE_EXT(name, data)      data;
        #include "lwevt_type.h"
        const unsigned int dummy;               /*!< Dummy element if no others are used by user */
    } msg;                                      /*!< Message union for extended event types */
} lwevt_t;

/**
 * \brief           Event callback function prototype
 */
typedef void (*lwevt_fn)(lwevt_t* evt);

void        lwevt_init(void);
uint8_t     lwevt_register(lwevt_fn evt_fn);
lwevt_t*    lwevt_get_handle(void);
uint8_t     lwevt_dispatch(lwevt_type_t type);
uint8_t     lwevt_dispatch_ex(lwevt_t* e, lwevt_type_t type);

/**
 * \}
 */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* LWEVT_HDR_H */
